/*
 * 文件名：SpringContextManager.java
 * 版权：Copyright 2006-2011 AsiaInfo Tech. Co. Ltd. All Rights Reserved. 
 * 描述： SpringContextManager.java
 * 修改人：齐鹏飞
 * 修改时间：2011-9-8
 * 修改内容：新增
 */
package com.fengxing.ams.pub.manager;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * spring上下文
 * <p>
 * spring上下文
 * <p>
 * 
 * <pre>
 * </pre>
 * 
 * @author 齐鹏飞
 * @version CTMS V100R001 2011-9-8
 * @since CTMS V100R001C01
 */
@Component
public class SpringContextManager implements ApplicationContextAware {
	/**
	 * spring context
	 */
	public static ApplicationContext webContext;
	
	public static void initContext(ApplicationContext webContent) {
		SpringContextManager.webContext = webContent;
	}

	/**
	 * 
	 * 获取bean
	 * 
	 * @param <T>
	 *            返回类型
	 * @param clazz
	 *            bean类型
	 * @return 返回bean实例
	 */
	public static <T> T getBean(Class<T> clazz) {
		return webContext.getBean(clazz);
	}

	/**
	 * 
	 * 获取bean
	 * 
	 * @param <T>
	 *            返回类型
	 * @param beanName
	 *            bean名称
	 * @return 返回bean实例
	 */
	public static <T> T getBean(String beanName) {
		return (T) webContext.getBean(beanName);
	}

	@Override
	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
		webContext = arg0;
	}
}
